package com.study.zzedu.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.study.zzedu.R;
import com.study.zzedu.entity.CourseDetailItem;

import java.util.List;

public class CourseDetailAdapter extends RecyclerView.Adapter<CourseDetailAdapter.MViewHolder> {

    private List<CourseDetailItem> m;
    public CourseDetailAdapter(List<CourseDetailItem> mList) {
        this.m = mList;
    }

    public MViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_course_item,parent,false);
        MViewHolder holder = new MViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MViewHolder holder, int position) {
        if(m.size()<1)
            return;
        CourseDetailItem mCourseDetailItem = m.get(position);

        holder.leftCourseDetailItem_key.setText(mCourseDetailItem.getKey());
        if(mCourseDetailItem.getType().equals(CourseDetailItem.TYPE_STRING)){
            holder.leftCourseDetailItem_value.setVisibility(View.VISIBLE);
            holder.leftCourseDetailItem_value.setText(mCourseDetailItem.getValue());
            holder.imageView.setVisibility(View.GONE);
        }else {
            holder.imageView.setVisibility(View.VISIBLE);
            holder.leftCourseDetailItem_value.setVisibility(View.GONE);
            //holder.imageView.setBackground();
        }
    }

    @Override
    public int getItemCount() {
        return m.size();
    }

    public class MViewHolder extends RecyclerView.ViewHolder{
        private TextView leftCourseDetailItem_key,leftCourseDetailItem_value;
        private ImageView imageView;
        public MViewHolder(View mView) {
            super(mView);
            leftCourseDetailItem_key = (TextView) mView.findViewById(R.id.tv_jhh_key);
            leftCourseDetailItem_value = (TextView) mView.findViewById(R.id.tv_jhh_value);
            imageView = (ImageView) mView.findViewById(R.id.iv_img);
        }
    }
}
